package com.saber.accumulator;

import com.saber.bean.Report;
import com.saber.bean.ReportItem;

/**
 *
 * @author
 *
 */
public class Sum implements ReportItemAccumulator {

	/**
	 *
	 */
	private ReportItem.AccumulatorType[] supported = new ReportItem.AccumulatorType[] {ReportItem.AccumulatorType.SUM};

	@Override
	public ReportItem.AccumulatorType[] getSupported() {
		return supported;
	}

	@Override
	public void accumulate(Report report, ReportItem reportItem, Object value) {
		Long v = null;
		Integer t = (Integer)value;
		Long old = Long.valueOf(reportItem.getValue());
		v = old + t;
		if(v < 0) {
			v = 0L;
		}
		reportItem.setValue(String.valueOf(v));
	}

}
